﻿using System;
using RPC;
using System.IO;

namespace Playground {
	public class Example1 {
		public Example1() {
			RPCManager manager = new RPCManager();//Create RPC Manager
			manager.Scan(typeof(RPCDateTimeReply));//Add known message


			using (Stream memory = new MemoryStream()) {//Create 'fake' stream
				DateTime now = DateTime.Now;//Create variables

				RPCDateTimeReply message = new RPCDateTimeReply();//Create Message that needs to be sending
				message.Date = now;

				manager.Write(memory, message);//Send Message to stream.

				memory.Seek(0, SeekOrigin.Begin);// (DEBUG) Seek to the begining, so we can read the message

				RPCMessage msg = null;
				while ((msg = manager.Read(memory)) != null) {//Loop through stream.
					//Proccess
					bool equal1 = (msg == message);//False, 'message' is created by you, and 'msg' is created by framework. Not the same object.
					bool equal2 = ((RPCDateTimeReply)msg).Date == message.Date;//True, data is same.
				}
			}
		}
	}
}
